import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
// 模块化路由
import syncRoutesDepartments from './modules/departments'
import syncRoutesSettings from './modules/settings'
import syncRoutesEmployees from './modules/employees'
import syncRoutesPermission from './modules/permission'
import syncRoutesApprovals from './modules/approvals'
import syncRoutesAttendances from './modules/attendances'
import syncRoutesSalarys from './modules/salarys'
import syncRoutesSocial_securitys from './modules/social_securitys'
// 动态路由表  不同的用户可以访问不同的功能
export const asyncRoutes = [
  syncRoutesDepartments,
  syncRoutesSettings,
  syncRoutesEmployees,
  syncRoutesPermission,
  syncRoutesApprovals,
  syncRoutesAttendances,
  syncRoutesSalarys,
  syncRoutesSocial_securitys

]
export const constantRoutes = [
  {
    path: '/import',
    component: () => import('@/views/excel/upload-excel.vue'),
    hidden: true
  },
  {
    path: '/demo',
    component: () => import('@/views/demo/index.vue')
  },
  {
    path: '/login', // 路由懒加载中的魔法注释 通过在注释中指定webpackChunkName，可以人为设置这个文件的名字
    component: () => import(/* webpackChunkName:'login' */'@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  }

  // // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  // 将静态路由和动态路由合并
  routes: [...constantRoutes]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
// 清除路由的方法
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
